#!/bin/bash
#build cscope database for hotspot code

#sanity check, this script is used in hotspot/src directory
if [ -d share -a -d os -a -d cpu -a -d os_cpu ] ; then
    echo "sanity check passed"
else
    echo "not a hotspot src direcoty"
    exit -1
fi

# check openjdk based on VCS
hs_root=`hg root`
parent_dir=`dirname $PWD`
openjdk=0
if [ x$hs_root = x$parent_dir ];then
  # I'm in mercurial
  openjdk=1
else
  # todo:gurantee we use subverion 
  openjdk=0
fi
#remove cscope tmp file
rm -f cscope.tmp cscope.files cscope.in.out cscope.out cscope.po.out

#generate file list
find . -name "*.[ch]pp" > cscope.tmp
if [ $openjdk -eq 1 ];then
   # I only care about linux_x64
   sed -e '/solaris/d' cscope.tmp|sed -e '/windows/d'|sed -e '/win32/d'|sed -e '/sparc/d'|sed -e '/zero/d'|sed -e '/shark/d'|sed -e '/arm/d'|sed -e '/ppc/d'|sed -e '/c1/d'|sed -e '/adlc/d' > cscope.files
else
   # only for hpux_ia64
   sed -e '/solaris/d' cscope.tmp|sed -e '/windows/d'|sed -e '/win32/d'|sed -e '/linux/d'|sed -e '/vms/d'|sed -e '/sparc/d'|sed -e '/zero/d'|sed -e '/shark/d'|sed -e '/x86/d'|sed -e '/pa64/d'|sed -e '/arm/d'|sed -e '/ppc/d'|sed -e '/c1/d'|sed -e '/adlc/d' > cscope.files
fi
cscope -bkqu

#remove tmp file
rm -f cscope.tmp